﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace DebugLogger
{
    public class DebugLogger
    {

        public DebugLogger(string logFilePath)
        {
            LogFilePath = logFilePath;
            writer = null;
        }
        
        public string LogFilePath { get; set; }

        public string HowToConsultLog
        {
            get { return String.Format("Log file is {0}", Path.GetFullPath(LogFilePath)); }
        }

        public bool IsOpened { get { return writer != null; } }

        private TextWriter writer;

        public void LogMessage(string message)
        {
            if (IsOpened)
            {
                writer.WriteLine("{0} : Message : {1}", DateTime.Now, message);
            }
        }

        public void LogError(string error)
        {
            if (IsOpened)
            {
                writer.WriteLine("{0} : ERROR : {1}", DateTime.Now, error);
            }
        }


        public void Open()
        {
            writer = new StreamWriter(LogFilePath, true);
            writer.WriteLine("\n\nNEW LOG SESSION {0}\n\n", DateTime.Now);
        }

        public void Close()
        {
            writer.WriteLine("\n\nEND LOG SESSION {0}\n\n", DateTime.Now);
            writer.Close();
            writer.Dispose();
            writer = null;
        }
    }
}
